package info.brenstar.boxedin.core;

import info.brenstar.boxedin.util.Trig;

import org.newdawn.slick.geom.Point;


public abstract class GravitySprite extends Sprite {
	
	protected double gravity;
	protected double gravity_direction;
	protected double delta_gravity;
	protected double gravity_max;
	
	public GravitySprite() {
		super();
	}
	
	public GravitySprite(float x, float y) {
		super(x, y);
	}
	
	protected void applyGravity() {
		if (gravity < gravity_max - delta_gravity) {
			gravity += delta_gravity;
		} else {
			gravity = gravity_max;
		}
		Point location = nextFall();
		x = location.getX();
		y = location.getY();
		
		/*float x = location.getX(), y = location.getY();
		x += Trig.lendir_x(gravity, gravity_direction);
		y += Trig.lendir_y(gravity, gravity_direction);
		location.setX(x);
		location.setY(y);*/
	}
	
	protected Point nextFall() {
		Point p = new Point(x, y);
		float x = p.getX(), y = p.getY();
		
		x += Trig.lendir_x(gravity, gravity_direction);
		y += Trig.lendir_y(gravity, gravity_direction);
		p.setX(x);
		p.setY(y);
		
		return p;
	}

}
